<template>
	<view class="warp">
		<!-- #ifdef APP-PLUS -->
		<view class="title-contents"><view class="top-view status"></view></view>
		<!-- #endif -->
		<view class="login-phone form-wapper">

			<view class="phone input-wapper">
				<view class="lside"><text class="iconfont icon-mima2"></text></view>
				<view class="mobile rside"><input v-model="oldPassword" placeholder-class="input-placeholder" 
				type="password" 
				 placeholder="请输入原密码" /></view>
			</view>
			<view class="phone input-wapper">
				<view class="lside"><text class="iconfont icon-mima2"></text></view>
				<view class="mobile rside"><input v-model="newPassword" placeholder-class="input-placeholder" type="password" 
				 placeholder="请输入新密码" /></view>
			</view>
			<view class="phone input-wapper">
				<view class="lside"><text class="iconfont icon-mima2"></text></view>
				<view class="mobile rside"><input v-model="newPasswordtwo" placeholder-class="input-placeholder" type="password" 
				 placeholder="请再次输入新密码" /></view>
			</view>
		</view>

		<button type="primary" class="login-btn" @click="submit">修改</button>

	</view>
</template>
<script>
	import {updatePwd} from '@/api/index.js'
	export default{
		data(){
			return{
				oldPassword:'',
				newPassword:'',
				newPasswordtwo:''
			}
		},
		onLoad() {
			
		},
		methods:{
			submit(){
				let {newPassword,oldPassword,newPasswordtwo} = this
				// console.log(oldPassword)
				if(!oldPassword){
					this.$u.toast('请输入旧密码');
					return;
				}
				if(!/^\w{6,12}$/.test(oldPassword)){
					this.$u.toast('旧密码格式错误');
					return;
				}
				if(!newPassword){
					this.$u.toast('请输入新密码');
					return;
				}
				if(!/^\w{6,12}$/.test(newPassword)){
					this.$u.toast('新密码格式错误');
					return;
				}
				if(!newPasswordtwo){
					this.$u.toast('请再次输入新密码');
					return;
				}
				if(newPassword!==newPasswordtwo){
					this.$u.toast('两次密码输入不一致');
					return;
				}
				// let {newPassword,oldPassword} = this
				let uid = uni.getStorageSync('uid')
				updatePwd({newPassword,uid,oldPassword}).then(res=>{
					if(res.code==0){
						this.$u.toast('修改成功')
						let {token,tokenExpired} = res;
						uni.setStorageSync('token',token)
						uni.setStorageSync('tokenExpired',tokenExpired)
						uni.navigateBack({delta:1})
					}
				})
			}
		}
	}
</script>
<style lang="scss">
@import  "login.scss"
</style>
